package com.lmscn.lms.api.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

/**
 * Created by Czl on 2015/7/25.
 */
@SuppressWarnings("serial")
public class CourseCommentCkGood extends Model<CourseCommentCkGood> {

    public static final CourseCommentCkGood dao = new CourseCommentCkGood();

    /**
     * 保存评论点赞
     * @param commentCkGood
     * @param commentId
     * @param studentId
     * @param courseId
     */
    public void saveCkGood(CourseCommentCkGood commentCkGood,Long commentId,Long studentId,Long courseId){
        commentCkGood.set("comment_id",commentId);
        commentCkGood.set("course_id",courseId);
        commentCkGood.set("student_id",studentId);
        commentCkGood.remove("id").save();
    }

    /**
     * 查找是否对评论点赞
     * @param courseId
     * @param studentId
     * @param commentId
     * @return
     */
    public CourseCommentCkGood getCommentCkGood(Long courseId,Long studentId,Long commentId){
        return dao.findFirst("select * from t_course_comment_ckgood " +
                "where comment_id =? and course_id=? and student_id =?",commentId,courseId,studentId);

    }
    
    /**
     * 获取评论被点赞的数量
     * @param commentId
     * @return
     */
    public long getCommentCkGoodNumByID(Long commentId) {
    	String sql = " SELECT count(*) FROM t_course_comment_ckgood t WHERE t.comment_id = ? ";
//    	List<CourseCommentCkGood> goodList = dao.find(sql,commentId);
//    	return goodList.size();
    	
    	return Db.queryLong(sql, commentId);
    }
}
